<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .echart{
            width: 500px;
            height: 500px;
        }
    </style>
</head>
<body>
世界地图
<div class="echart" id="main-world-map"></div>
<script src="../jquery.min.js" charset="utf-8"></script>
<script src="../echarts.js"></script>
<script src="world.js"></script>
<script>
  //初始化echarts
  var myChartMap;
  worldMap(); //世界地图
  function worldMap() {
    // 世界地图
    if (myChartMap != null && myChartMap != "" && myChartMap != undefined) {
      myChartMap.dispose();
    }
    var echartDataArr = [];
    //列出国家列表-获得国家名字
    // ajaxCountryList().then(function (contryList) {
      var i = 0;
      // repeat();
      function repeat() {
        if (i < contryList.length) {
          patentCount(i);
          function patentCount(patentI) {
            // console.log(contryList[patentI].name);
            ajaxPatentCountByCountry(contryList[patentI][1]).then(function (PatentCount) {
              // console.log(PatentCount);
              // console.log('s',contryList);
              geolocation(contryList[patentI][1], PatentCount);
              i++;
              repeat(); //重复调用函数
              function geolocation(name, num) {
                //世界国家英文全称
                var geolocation = [
                  ["AO", "Angola"],
                  ["AF", "Afghanistan"],
                  ["AL", "Albania"],
                  ["DZ", "Algeria"],
                  ["AD", "Andorra"],
                  ["AI", "Anguilla"],
                  ["AG", "Barbuda Antigua"],
                  ["AR", "Argentina"],
                  ["AM", "Armenia"],
                  ["AU", "Australia"],
                  ["AT", "Austria"],
                  ["AZ", "Azerbaijan"],
                  ["BS", "Bahamas"],
                  ["BH", "Bahrain"],
                  ["BD", "Bangladesh"],
                  ["BB", "Barbados"],
                  ["BY", "Belarus"],
                  ["BE", "Belgium"],
                  ["BZ", "Belize"],
                  ["BJ", "Benin"],
                  ["BM", "Bermuda Is."],
                  ["BO", "Bolivia"],
                  ["BW", "Botswana"],
                  ["BR", "Brazil"],
                  ["BN", "Brunei"],
                  ["BG", "Bulgaria"],
                  ["BF", "Burkina-faso"],
                  ["MM", "Burma"],
                  ["BI", "Burundi"],
                  ["CM", "Cameroon"],
                  ["CA", "Canada"],
                  ["CF", "Central African Republic"],
                  ["TD", "Chad"],
                  ["CL", "Chile"],
                  ["CN", "China"],
                  ["CO", "Colombia"],
                  ["CG", "Congo"],
                  ["CK", "Cook Is."],
                  ["CR", "Costa Rica"],
                  ["CU", "Cuba"],
                  ["CY", "Cyprus"],
                  ["CZ", "Czech Republic"],
                  ["DK", "Denmark"],
                  ["DJ", "Djibouti"],
                  ["DO", "Dominica Rep."],
                  ["EC", "Ecuador"],
                  ["EG", "Egypt"],
                  ["SV", "EI Salvador"],
                  ["EE", "Estonia"],
                  ["ET", "Ethiopia"],
                  ["FJ", "Fiji"],
                  ["FI", "Finland"],
                  ["FR", "France"],
                  ["GF", "French Guiana"],
                  ["GA", "Gabon"],
                  ["GM", "Gambia"],
                  ["GE", "Georgia"],
                  ["DE", "Germany"],
                  ["GH", "Ghana"],
                  ["GI", "Gibraltar"],
                  ["GR", "Greece"],
                  ["GD", "Grenada"],
                  ["GU", "Guam"],
                  ["GT", "Guatemala"],
                  ["GN", "Guinea"],
                  ["GY", "Guyana"],
                  ["HT", "Haiti"],
                  ["HN", "Honduras"],
                  ["HK", "Hongkong"],
                  ["HU", "Hungary"],
                  ["IS", "Iceland"],
                  ["IN", "India"],
                  ["ID", "Indonesia"],
                  ["IR", "Iran"],
                  ["IQ", "Iraq"],
                  ["IE", "Ireland"],
                  ["IL", "Israel"],
                  ["IT", "Italy"],
                  ["JM", "Jamaica"],
                  ["JP", "Japan"],
                  ["JO", "Jordan"],
                  ["KH", "Kampuchea (Cambodia )"],
                  ["KZ", "Kazakstan"],
                  ["KE", "Kenya"],
                  ["KR", "Korea"],
                  ["KW", "Kuwait"],
                  ["KG", "Kyrgyzstan"],
                  ["LA", "Laos"],
                  ["LV", "Latvia"],
                  ["LB", "Lebanon"],
                  ["LS", "Lesotho"],
                  ["LR", "Liberia"],
                  ["LY", "Libya"],
                  ["LI", "Liechtenstein"],
                  ["LT", "Lithuania"],
                  ["LU", "Luxembourg"],
                  ["MO", "Macao"],
                  ["MG", "Madagascar"],
                  ["MW", "Malawi"],
                  ["MY", "Malaysia"],
                  ["MV", "Maldives"],
                  ["ML", "Mali"],
                  ["MT", "Malta"],
                  ["MU", "Mauritius"],
                  ["MX", "Mexico"],
                  ["MD", "Moldova"],
                  ["MC", "Monaco"],
                  ["MN", "Mongolia"],
                  ["MS", "Montserrat Is."],
                  ["MA", "Morocco"],
                  ["MZ", "Mozambique"],
                  ["NA", "Namibia"],
                  ["NR", "Nauru"],
                  ["NP", "Nepal"],
                  ["NL", "Netherlands"],
                  ["NZ", "New Zealand"],
                  ["NI", "Nicaragua"],
                  ["NE", "Niger"],
                  ["NG", "Nigeria"],
                  ["KP", "North Korea"],
                  ["NO", "Norway"],
                  ["OM", "Oman"],
                  ["PK", "Pakistan"],
                  ["PA", "Panama"],
                  ["PG", "Papua New Cuinea"],
                  ["PY", "Paraguay"],
                  ["PE", "Peru"],
                  ["PH", "Philippines"],
                  ["PL", "Poland"],
                  ["PF", "French Polynesia"],
                  ["PT", "Portugal"],
                  ["PR", "Puerto Rico"],
                  ["QA", "Qatar"],
                  ["RO", "Romania"],
                  ["RU", "Russia"],
                  ["LC", "Saint Lueia"],
                  ["VC", "Saint Vincent"],
                  ["SM", "San Marino"],
                  ["ST", "Sao Tome and Principe"],
                  ["SA", "Saudi Arabia"],
                  ["SN", "Senegal"],
                  ["SC", "Seychelles"],
                  ["SL", "Sierra Leone"],
                  ["SG", "Singapore"],
                  ["SK", "Slovakia"],
                  ["SI", "Slovenia"],
                  ["SB", "Solomon Is."],
                  ["SO", "Somali"],
                  ["ZA", "South Africa"],
                  ["ES", "Spain"],
                  ["LK", "Sri Lanka"],
                  ["SD", "Sudan"],
                  ["SR", "Suriname"],
                  ["SZ", "Swaziland"],
                  ["SE", "Sweden"],
                  ["CH", "Switzerland"],
                  ["SY", "Syria"],
                  ["TW", "Taiwan"],
                  ["TJ", "Tajikstan"],
                  ["TZ", "Tanzania"],
                  ["TH", "Thailand"],
                  ["TG", "Togo"],
                  ["TO", "Tonga"],
                  ["TT", "Trinidad and Tobago"],
                  ["TN", "Tunisia"],
                  ["TR", "Turkey"],
                  ["TM", "Turkmenistan"],
                  ["UG", "Uganda"],
                  ["UA", "Ukraine"],
                  ["AE", "United Arab Emirates"],
                  ["GB", "United Kiongdom"],
                  ["US", "United States"],
                  ["UY", "Uruguay"],
                  ["UZ", "Uzbekistan"],
                  ["VE", "Venezuela"],
                  ["VN", "Vietnam"],
                  ["YE", "Yemen"],
                  ["YU", "Yugoslavia"],
                  ["ZW", "Zimbabwe"],
                  ["ZR", "Zaire"],
                  ["ZM", "Zambia"]
                ];
                for (var j = 0; j < geolocation.length; j++) {
                  if (geolocation[j][0] == name) {
                    // return geolocation[i][1];
                    echartDataArr.push({name: geolocation[j][1], value: num});
                    // console.log(echartDataArr);
                  }
                }
              };
            });
          }
        } else {
          echartSetOption();
          console.log('国家', echartDataArr);
        }
      }
    echartSetOption()
      //构建地图echarts
      function echartSetOption() {
        // setTimeout(function(){
        // echartDataArr=[{ name: 'Canada', value: 28397.812 }]
        myChartMap = echarts.init(document.getElementById('main-world-map'));
        option = {
          title: {
            sublink: 'http://esa.un.org/wpp/Excel-Data/population.htm',
            left: 'center',
            top: 'top'
          },
          tooltip: {
            //  显示data的value
            trigger: 'item',
            formatter: function (params) {
              var value = (params.value + '').split('.');
              if (value[0] == 'NaN') {
                value = ['0', '0'];
              } else if (value.length < 2) {
                value = [value[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,'), '0']
              }
              // console.log(value);
              // value = value[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + '.' + value[1];
              value = value[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,');
              return params.seriesName + '<br/>' + params.name + ' : ' + value;
            }
          },
          visualMap: {
            show: false,
            min: 0,
            // max: (isEmpty(echartDataArr[0]) ? '1' : echartDataArr[0].value),
            max: 100,
            text: ['High', 'Low'],
            realtime: false,
            calculable: true,
            // color: ['orangered', 'yellow', 'lightskyblue']
            color: ['orangered', 'white']
          },
          series: [{
            name: '专利数量',
            type: 'map',
            mapType: 'world',
            roam: true,
            itemStyle: {
              emphasis: {label: {show: true}}
            },
            data:[{ name: 'Canada', value: 28397.812 }],
            // data: echartDataArr
          }]
        };
        myChartMap.setOption(option);
        // },100);
      }
    // });
  };
</script>
</body>
</html>